package com.zzp.zjs_bos.service.impl;

import java.sql.Timestamp;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zzp.zjs_bos.dao.IDecidedDao;
import com.zzp.zjs_bos.dao.INoticebillDao;
import com.zzp.zjs_bos.dao.IWorkbillDao;
import com.zzp.zjs_bos.domain.Decidedzone;
import com.zzp.zjs_bos.domain.Noticebill;
import com.zzp.zjs_bos.domain.Staff;
import com.zzp.zjs_bos.domain.Workbill;
import com.zzp.zjs_bos.service.INoticebillService;

import cn.itcast.crm.service.CustomerService;

@Service
@Transactional
public class NoticebillServiceImpl implements INoticebillService {

	@Resource
	private INoticebillDao noticebillDao;
	
	@Resource
	private CustomerService customerService;
	
	@Resource
	private IDecidedDao decidedDao;
	
	@Resource
	private IWorkbillDao workbillDao;
	
	public void save(Noticebill model) {
		noticebillDao.save(model);
		String decidedzone_id = customerService.findByDecidedzone(model.getPickaddress());
		if(decidedzone_id != null){
			Decidedzone decidedzone = decidedDao.findById(decidedzone_id);
			Staff staff = decidedzone.getStaff();
			model.setStaff(staff);
			model.setOrdertype("自动");
			
			Workbill workbill = new Workbill();
			workbill.setStaff(staff);
			workbill.setBuildtime(new Timestamp(System.currentTimeMillis()));
			workbill.setAttachbilltimes(0);
			workbill.setNoticebill(model);
			workbill.setType("new");
			workbill.setPickstate("未取件");
			workbill.setRemark(model.getRemark());
			workbillDao.save(workbill);
		}
		
	}

}
